import exp from "constants";
export function isMore(page, limit, total) {
	return page * limit < total;
}
export function multipleChoiceChange(arr, value, max = -1) {
	if (!arr.includes(value)) {
		if (max == -1 || arr.length < max) {
			arr.push(value)
		} else {
			uni.showToast({
				title: `最多只能选择${max}个`,
				icon: 'none'
			})
		}
	} else {
		const index = arr.indexOf(value)
		arr.splice(index, 1)
	}
	return arr;
}
export function getCustomNavData() {
	let result = {};
	uni.getSystemInfo({
		success(e) {
			let myStatusBar = 0;
			let myCustomBar = 0;
			let myNvaMartom = 0;
			let myNavHeight = 0;
			let myNavWidth = 0;
			let custom = uni.getMenuButtonBoundingClientRect();
			myStatusBar = e.statusBarHeight;
			myNavHeight = custom.height;
			myNavWidth = custom.width;
			myNvaMartom = custom.top - e.statusBarHeight;
			myCustomBar = (myNvaMartom * 2 + custom.height) - 2;
			result.statusBar = myStatusBar * 750 / wx.getSystemInfoSync().windowWidth; //顶部状态栏高度
			result.customBar = (myCustomBar * 750 / wx.getSystemInfoSync().windowWidth) + 12; //导航栏高度
			result.nvaMartom = myNvaMartom * 750 / wx.getSystemInfoSync().windowWidth; //胶囊上边距
			result.navHeight = myNavHeight * 750 / wx.getSystemInfoSync().windowWidth; //胶囊按钮高度
			result.navWidth = myNavWidth * 750 / wx.getSystemInfoSync().windowWidth; //胶囊按钮宽度
			result.navMarRight = 750 - (custom.right * 750 / wx.getSystemInfoSync().windowWidth); //胶囊右边距
			result.pageMagTop = result.customBar + result.statusBar; //页面内容距离顶部的上边距，导航栏全部高度
		}
	})
	return result
}
export function showDevelopingTips() {
	uni.showToast({
		title: '该功能正在研发中QWQ~',
		icon: 'none'
	})
}
export function get24HoursTime(time) {
	if (time.indexOf('上午') != -1) {
		time = time.replace('上午', '');
		let arr = time.split(':');
		arr[0] = arr[0] == '12' ? '00' : arr[0];
		arr[0] = arr[0].length == 2 ? arr[0] : '0' + arr[0];
		time = arr.join(':')
	}
	if (time.indexOf('下午') != -1) {
		time = time.replace('下午', '');
		let arr = time.split(':');
		arr[0] = arr[0] == '12' ? arr[0] : arr[0] * 1 + 12;
		arr[0] = arr[0] == '24' ? '00' : arr[0].toString()
		arr[0] = arr[0].length == 2 ? arr[0] : '0' + arr[0];
		time = arr.join(':')
	}
	return time;
}
export function getCurrentTime(fields = 's', time = null) {
	const date = time ? new Date(time) : new Date();
	let str = '';
	let y = date.getFullYear().toString();
	let m = (date.getMonth() + 1).toString();
	m = m.length == 1 ? '0' + m : m
	let d = date.getDate().toString();
	d = d.length == 1 ? '0' + d : d
	let h = date.getHours().toString();
	h = h.length == 1 ? '0' + h : h
	let i = date.getMinutes().toString();
	i = i.length == 1 ? '0' + i : i
	let s = date.getSeconds().toString();
	s = s.length == 1 ? '0' + s : s
	if (fields == 'y') {
		str = y;
	}
	if (fields == 'm') {
		str = y + '-' + m
	}
	if (fields == 'd') {
		str = y + '-' + m + '-' + d
	}
	if (fields == 'h') {
		str = y + '-' + m + '-' + d + ' ' + h
	}
	if (fields == 'i') {
		str = y + '-' + m + '-' + d + ' ' + h + ':' + i
	}
	if (fields == 's') {
		str = y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s
	}
	return str;
}
export function getYearsAgo(year) {
	const date = new Date();
	date.setFullYear(date.getFullYear() - 20);
	return getCurrentTime('d', date);
}
export function showToast(msg, callback = function() {

}) {
	uni.showToast({
		title: msg,
		icon: 'none',
		duration: 2000,
		success(e) {
			setTimeout(function() {
				callback()
			}, 2000)
		}
	})
}
export default {
	showDevelopingTips
}